import {
    FishLevelConfigs, FishLooksConfigs,
    LingGenConfigs, PeculiarityConfigs,
    PeculiaritySkillConfigs, PersonalityConfigs, SkillConfigs,
    TalentConfigs
} from "db://assets/proto/shared/v1/configs";
import {GlobalConfigsLoader} from "db://assets/script/global-configs-loader";
import Long from "long";
import {cmm} from "db://assets/script/utils/cmm";

export class FishConfigsLoader {

    findFishLevelConfigsByLevel(level: number): FishLevelConfigs | undefined {
        const flc = GlobalConfigsLoader.instance.getFishLevelConfigs()
        return flc.get(level.toString())
    }

    findFishLooksConfig(styleId: Long): FishLooksConfigs | undefined {
        const flc = GlobalConfigsLoader.instance.getFishLooksConfigs()
        return flc.get(styleId.toString())
    }

    findTalentConfig(talentId: number): TalentConfigs | undefined {
        const tc = GlobalConfigsLoader.instance.getTalentConfigs()
        return tc.get(talentId.toString())
    }

    findPersonalityName(personalityId: number): string {
        const pc = GlobalConfigsLoader.instance.getPersonalityConfigs()
        return pc.get(personalityId.toString())?.name || ''
    }

    findLingGenConfig(lingGenId: Long): LingGenConfigs | undefined {
        const lgc = GlobalConfigsLoader.instance.getLingGenConfigs()
        return lgc.get(lingGenId.toString())
    }

    findPeculiarityConfigs(peculiarityId: Long): PeculiarityConfigs | undefined {
        const pc = GlobalConfigsLoader.instance.getPeculiarityConfigs()
        return pc.get(peculiarityId.toString())
    }

    findPeculiaritySkillConfigs(peculiarityId: Long): PeculiaritySkillConfigs[] | undefined {
        const pc = GlobalConfigsLoader.instance.getPeculiaritySkillConfigs()
        return cmm.map2array(pc, (_, value) => {
            return value
        })
    }

    findSkillConfig(skillId: Long): SkillConfigs | undefined {
        const sc = GlobalConfigsLoader.instance.getSkillsConfigs()
        return sc.get(skillId.toString())
    }
}

export const fishConfigsLoader = new FishConfigsLoader();